import requests
import json
import urllib
import subprocess,time
import os
from datetime import datetime
from tkinter import messagebox
def listDir(path,extensions,reuslts = []):
    for x in os.listdir(path):
        filepath = path+"/"+x
        if os.path.isfile(filepath):
            for e in extensions:
                if x.endswith("."+e):
                    reuslts.append(filepath)
                    break
        elif os.path.isdir(filepath):
            listDir(filepath,extensions=extensions,reuslts=reuslts)
        else:
            print(f'other====:{filepath}')
    return reuslts
areaId = "410400"
Authorization = "bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJsb2dpblVzZXIiOnsiaWQiOiI0ODYwODUzMzcwMDU2ODY3ODQiLCJ1c2VyTmFtZSI6IuWRqOaYgiIsIm1vYmlsZSI6IjE1OTgxOTMxMzI1IiwiYWNjb3VudCI6Inpob3VhbmciLCJpc1VzaW5nIjoxLCJkZWxGbGFnIjowLCJncm91cGluZ3MiOlt7ImFyZWFJZCI6IjAiLCJuYW1lIjoiMCJ9XSwicGFzc3dvcmQiOm51bGwsInVzZXJuYW1lIjoiNDg2MDg1MzM3MDA1Njg2Nzg0IiwiZW5hYmxlZCI6dHJ1ZSwiYXV0aG9yaXRpZXMiOm51bGwsImFjY291bnROb25FeHBpcmVkIjp0cnVlLCJhY2NvdW50Tm9uTG9ja2VkIjp0cnVlLCJjcmVkZW50aWFsc05vbkV4cGlyZWQiOnRydWV9LCJ1c2VyX25hbWUiOiI0ODYwODUzMzcwMDU2ODY3ODQiLCJzY29wZSI6WyJhbGwiLCJyZWFkIiwid3JpdGUiXSwibG9naW5Vc2VySWQiOiI0ODYwODUzMzcwMDU2ODY3ODQiLCJleHAiOjE2NjQ0NTAzODMsInV1SWQiOiI1ZmI5ZGM4OS02Nzg4LTRhYzktOWRlNC00Yjk0OGIzMTlkODciLCJqdGkiOiI1ZmI5ZGM4OS02Nzg4LTRhYzktOWRlNC00Yjk0OGIzMTlkODciLCJjbGllbnRfaWQiOiJ6eXNvZnQifQ.NJjBwZzU6SKRsABe5TePQshIaSQWoNXgAqE9-nZLhgA"
header = {
    "Accept": "application/json, text/plain, */*",
    "Authorization": Authorization,
    "Accept-Encoding": "gzip, deflate, br",
    "Accept-Language": "zh-CN,zh-Hans;q=0.9",
    "Host": "lzpt.hnzx.gov.cn",
    "Origin": "https://lzpt.hnzx.gov.cn",
    "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.6.1 Safari/605.1.15",
    "Referer": "https://lzpt.hnzx.gov.cn/henan-platform/",
    "u-login-areaId": areaId,
    "clientTypeId": "zhengxieplatform"
}
# 编辑手机app管理的菜单
def editApp(origin={},isShow="1"):
    if "parentId" not in origin : 
        return "无数据"
    if len(isShow) == 0 : 
        return "无数据"
    dic =  dict({
        "id": origin["id"],
        "parentId": origin["parentId"],
        "title": origin["title"],
        "iconUrl": origin["iconUrl"].split("=")[-1],
        "type": origin["type"],
        "sort": origin["sort"],
        "infoUrl": origin["infoUrl"],
        "infoUrl2": origin["infoUrl2"],
        "position": origin["position"],
        "moduleColumn": origin["moduleColumn"],
        "isShow": isShow,
        "isPublic": origin["isPublic"],
        "areaId": origin["areaId"],
        "remarks": origin["remarks"],
        "nullValueFields":"",
    })
    try:
        response = requests.post("https://lzpt.hnzx.gov.cn/platform-lzt/module/edit",data=dic,headers=header)
    except urllib.error.URLError as e:
        # if isinstance(e.reason, socket.timeout):
        print('TIME OUT',e);
    else:
        json1 = json.loads(response.text)
        return json1

# 隐藏某个手机端菜单app
def editAppHiddenToSystem(isEdit=True):
    arr = [
        {
            "name":"重点工作管理",
            "mod":"机关办公"
        },
    ]
    for x in arr:
        if isEdit:
            print(editApp(origin=getApp(getAppId(name=x["name"],mod =x["mod"])),isShow="0"))
        # # 不可立刻验证，因此最好循环处理
        else:
            print(getApp(getAppId(name=x["name"],mod =x["mod"]))['isShow'] == "0")
        time.sleep(2)
# 手机app管理，获取当前区域的上级菜单
def getTopMenu(areaId,name):
    try:
        response = requests.post("https://lzpt.hnzx.gov.cn/platform-lzt/module/tree",data=dict({"areaId": areaId}),headers=header)
    except urllib.error.URLError as e:
        # if isinstance(e.reason, socket.timeout):
        print('TIME OUT',e);
    else:
        json1 = json.loads(response.text)
        for x in json1['data']:
            if x["name"] == name:
                return x
    return ""

# 编辑手机app管理的菜单，获取默认配置信息
# 模块名称,所在模块，菜单位置,排序,功能栏目，上层菜单，h5链接，图片地址
def getMobileAddConfig(title,moduleName,positionName,sort,funcName,topMenuName,link,image):
    module = {}
    position = {}
    func = {}
    topMenu = {}
    try:
        response = requests.post("https://lzpt.hnzx.gov.cn/platform-lzt/dictionary/pubkvs?",data=dict({"types": "module_type,module_position_type,module_column"}),headers=header)
    except urllib.error.URLError as e:
        # if isinstance(e.reason, socket.timeout):
        print('TIME OUT',e);
    else:
        json1 = json.loads(response.text)
        for x in json1['data']["module_type"]:
            if x["value"] == moduleName:
                module = x
        for x in json1['data']["module_position_type"]:
            if x["value"] == positionName:
                position = x
        for x in json1['data']["module_column"]:
            if x["value"] == funcName:
                func = x
    topMenu  = getTopMenu(areaId,name=topMenuName)
    if len(image) > 0 :
        imageUrl = uploadImage(image)["data"]["shortName"]
    return {
        "empty": 1,
        "id": "",
        "parentId": topMenu["id"],
        "title": title,
        "iconUrl": imageUrl,
        "type": module["id"],
        "sort": sort,
        "infoUrl": link,
        "infoUrl2": link,
        "position": position["id"],
        "moduleColumn": func["id"],
        "isShow": 0,
        "isPublic": 0,
        "areaId": areaId,
        "remarks": ""
    }
#手机app管理的菜单，添加单个条目
def addMobileApp(dic):
    try:
        response = requests.post("https://lzpt.hnzx.gov.cn/platform-lzt/module/add",data=dict(dic),headers=header)
    except urllib.error.URLError as e:
        # if isinstance(e.reason, socket.timeout):
        print('TIME OUT',e);
    else:
        json1 = json.loads(response.text)
    return json1
#手机app管理的菜单，添加多条
def addMobileApps(ip):
    arr = [
        # {
        #     "title" : "token", 
        #     "moduleName" : "功能区", 
        #     "positionName" : "首页中间", 
        #     "sort" : "1000", 
        #     "funcName" : "核心业务", 
        #     "topMenuName" : "功能区", 
        #     "link" : "http://"+ip+"/indexTest.html#/?token={{token}}&userId={{userId}}", 
        #     "image" : ""
        # },

        {
            "title" : "提案工作", 
            "moduleName" : "功能区", 
            "positionName" : "首页中间", 
            "sort" : "1101", 
            "funcName" : "核心业务", 
            "topMenuName" : "功能区", 
            "link" : "http://"+ip+"/proposal.html#/proposal-index?token={{token}}&userId={{userId}}", 
            "image" : "/Users/wangshuguan/Documents/政协部署/配图/移动端/提案工作ddd1.png"
        },
        {
            "title" : "社情民意", 
            "moduleName" : "功能区", 
            "positionName" : "首页中间", 
            "sort" : "1102", 
            "funcName" : "核心业务", 
            "topMenuName" : "功能区", 
            "link" : "http://"+ip+"/apply.html#/sqmy?token={{token}}&userId={{userId}}", 
            "image" : "/Users/wangshuguan/Documents/政协部署/配图/移动端/社情民意1.png"
        },
        {
            "title" : "委员履职", 
            "moduleName" : "功能区", 
            "positionName" : "首页中间", 
            "sort" : "1103", 
            "funcName" : "核心业务", 
            "topMenuName" : "功能区", 
            "link" : "http://"+ip+"/duty.html?token={{token}}&userId={{userId}}", 
            "image" : "/Users/wangshuguan/Documents/政协部署/配图/移动端/委员履职4ff11.png"
        },
        {
            "title" : "基础信息", 
            "moduleName" : "功能区", 
            "positionName" : "首页中间", 
            "sort" : "1104", 
            "funcName" : "核心业务", 
            "topMenuName" : "功能区", 
            "link" : "http://"+ip+"/apply.html#/jbxx?token={{token}}&userId={{userId}}", 
            "image" : "/Users/wangshuguan/Documents/政协部署/配图/移动端/00基础信息1.png"
        },



        {
            "title" : "会议管理", 
            "moduleName" : "功能区", 
            "positionName" : "首页中间", 
            "sort" : "1201", 
            "funcName" : "自建应用", 
            "topMenuName" : "功能区", 
            "link" : "http://"+ip+"/hyhd/#/pages/meeting/index?token={{token}}&userId={{userId}}", 
            "image" : "/Users/wangshuguan/Documents/政协部署/配图/移动端/会议管理.png"
        },
        {
            "title" : "活动管理", 
            "moduleName" : "功能区", 
            "positionName" : "首页中间", 
            "sort" : "1202", 
            "funcName" : "自建应用", 
            "topMenuName" : "功能区", 
            "link" : "http://"+ip+"/hyhd/#/pages/activity/index?token={{token}}&userId={{userId}}", 
            "image" : "/Users/wangshuguan/Documents/政协部署/配图/移动端/活动管理13444.png"
        },
        {
            "title" : "智慧党建", 
            "moduleName" : "功能区", 
            "positionName" : "首页中间", 
            "sort" : "1203", 
            "funcName" : "自建应用", 
            "topMenuName" : "功能区", 
            "link" : "http://"+ip+"/zhdjWb?token={{token}}&userId={{userId}}", 
            "image" : "/Users/wangshuguan/Documents/政协部署/配图/移动端/智慧党建.png"
        },
        {
            "title" : "政协书院", 
            "moduleName" : "功能区", 
            "positionName" : "首页中间", 
            "sort" : "1204", 
            "funcName" : "自建应用", 
            "topMenuName" : "功能区", 
            "link" : "http://"+ip+"/apply.html#/zxsy?token={{token}}&userId={{userId}}", 
            "image" : "/Users/wangshuguan/Documents/政协部署/配图/移动端/政协书院1221aavvaa1.png"
        },
        {
            "title" : "网上文史馆", 
            "moduleName" : "功能区", 
            "positionName" : "首页中间", 
            "sort" : "1205", 
            "funcName" : "自建应用", 
            "topMenuName" : "功能区", 
            "link" : "http://"+ip+"/duty.html#/history?token={{token}}&userId={{userId}}", 
            "image" : "/Users/wangshuguan/Documents/政协部署/配图/移动端/网上文史馆图标.png"
        },
        {
            "title" : "融媒体中心", 
            "moduleName" : "功能区", 
            "positionName" : "首页中间", 
            "sort" : "1206", 
            "funcName" : "自建应用", 
            "topMenuName" : "功能区", 
            "link" : "http://"+ip+"/proposal.html#/media-index?token={{token}}&userId={{userId}}", 
            "image" : "/Users/wangshuguan/Documents/政协部署/配图/移动端/融媒体中心4deeeeeafd.png"
        },




        {
            "title" : "政协云盘", 
            "moduleName" : "功能区", 
            "positionName" : "首页中间", 
            "sort" : "1301", 
            "funcName" : "机关办公", 
            "topMenuName" : "功能区", 
            "link" : "http://"+ip+"/zxyp.html#/pages/yunpan/index?token={{token}}&userId={{userId}}", 
            "image" : "/Users/wangshuguan/Documents/政协部署/配图/移动端/政协云盘50.png"
        },
        {
            "title" : "重点工作公开", 
            "moduleName" : "功能区", 
            "positionName" : "首页中间", 
            "sort" : "1302", 
            "funcName" : "机关办公", 
            "topMenuName" : "功能区", 
            "link" : "http://"+ip+"/apply.html#/zdgk?token={{token}}&userId={{userId}}", 
            "image" : "/Users/wangshuguan/Documents/政协部署/配图/移动端/重点工作公开2.png"
        },
        {
            "title" : "重点工作管理", 
            "moduleName" : "功能区", 
            "positionName" : "首页中间", 
            "sort" : "1303", 
            "funcName" : "机关办公", 
            "topMenuName" : "功能区", 
            "link" : "http://"+ip+"/apply.html#/zdgl?token={{token}}&userId={{userId}}", 
            "image" : "/Users/wangshuguan/Documents/政协部署/配图/移动端/重点工作管理sewref1.png"
        },
    ]
    for x in arr:
        dic = getMobileAddConfig(title = x["title"], moduleName = x["moduleName"], positionName = x["positionName"], sort = x["sort"], funcName = x["funcName"], topMenuName = x["topMenuName"], link = x["link"], image = x["image"])
        print(addMobileApp(dic))
        time.sleep(2)
#  从运维管理操作平台的menu中找出来模块确定，名称确定的对象，用于修改
def getMenus(name="",mod = ""):
    if len(name) == 0 or len(mod) == 0:
        print("无数据")
        return "{}"
    try:
        response = requests.post("https://lzpt.hnzx.gov.cn/platform-lzt/menu/tree",headers=header)
    except urllib.error.URLError as e:
        # if isinstance(e.reason, socket.timeout):
        print('TIME OUT',e);
    else:
        json1 = json.loads(response.text)
        for x in json1['data']:
            if x["name"] == "河南省智慧政协":
                for x1 in x['children']:
                    if x1["name"] == "操作平台":
                        for x2 in x1['children']:
                            if x2["name"] == name and x2["moduleColumnView"] == mod:
                                return x2
        return json1

#  获取运维管理操作平台的id
def getOperateId():
    
    try:
        response = requests.post("https://lzpt.hnzx.gov.cn/platform-lzt/menu/tree",headers=header)
    except urllib.error.URLError as e:
        # if isinstance(e.reason, socket.timeout):
        print('TIME OUT',e);
    else:
        json1 = json.loads(response.text)
        for x in json1['data']:
            if x["name"] == "河南省智慧政协":
                for x1 in x['children']:
                    if x1["name"] == "操作平台":
                        return x1["menuId"]
        return ""

# 运维工具里的操作平台app，根据模块名称获取id
def getModueId(name=""):
    
    try:
        response = requests.post("https://lzpt.hnzx.gov.cn/platform-lzt/dictionary/pubkvs?",data=dict({"types": "module_column"}),headers=header)
    except urllib.error.URLError as e:
        # if isinstance(e.reason, socket.timeout):
        print('TIME OUT',e);
    else:
        json1 = json.loads(response.text)
        for x in json1['data']["module_column"]:
            if x["value"] == name:
                return x["id"]
        return ""

# 编辑运维管理里的app，此处只改链接                
def editMenus(origin={},url=""):
    if "parentId" not in origin : 
        return "无数据"
    if len(url) == 0 : 
        return "无数据"
    dic =  dict({
        "id":origin["menuId"],
        "parentId":origin["parentId"],
        "name":origin["name"],
        "sort":origin["sort"],
        "moduleColumn":origin["moduleColumn"],
        "isPublic":1 if origin["isPublic"] else 0,
        "href": url,
        "iconUrl": origin["iconUrl"].split("=")[-1],
        "menuType": 1,
        "isShow": 1 if origin["isShow"] else 0,
        "nullValueFields": "color",
    })
    try:
        response = requests.post("https://lzpt.hnzx.gov.cn/platform-lzt/menu/edit?",data=dic,headers=header)
    except urllib.error.URLError as e:
        # if isinstance(e.reason, socket.timeout):
        print('TIME OUT',e);
    else:
        json1 = json.loads(response.text)
        return json1                

# 根据模块和名称获取appid
def getAppId(name="",mod = ""):
    if len(name) == 0 or len(mod) == 0:
        print("无数据")
        return "{}"
    try:
        response = requests.post("https://lzpt.hnzx.gov.cn/platform-lzt/module/list?",data=dict({"title":name,"type":"","pageNo":"1","pageSize":"20"}),headers=header)
    except urllib.error.URLError as e:
        # if isinstance(e.reason, socket.timeout):
        print('TIME OUT',e);
    else:
        json1 = json.loads(response.text)
        for x in json1['data']:
            if x["title"] == name and x["moduleColumnView"] == mod:
                return x["id"]
        return ""
# 根据appid获取app信息
def getApp(appId=""):
    if len(appId) == 0:
        print("无appId")
        return "{}"
    try:
        response = requests.post("https://lzpt.hnzx.gov.cn/platform-lzt/module/info/"+appId,headers=header)
    except urllib.error.URLError as e:
        # if isinstance(e.reason, socket.timeout):
        print('TIME OUT',e);
    else:
        json1 = json.loads(response.text)
        return json1['data']
# 改运维工具里的链接
def changeUrl(name="",mod = "",url=""):
    if len(name) == 0 or len(name) == 0 or len(url) == 0:
        print("数据缺少")
        return ""
    print(editMenus(origin=getMenus(name=name,mod = mod),url=url))
# 上传图片
def uploadImage(fileurl=""):
    if len(fileurl) == 0:
        print("图片地址错误")
        return ""
    try:
        response2 = requests.post("https://lzpt.hnzx.gov.cn/platform-lzt/file/uploadimg", files={'file': open(fileurl, 'rb')},headers=header)
    except urllib.error.URLError as e:
        # if isinstance(e.reason, socket.timeout):
        print('TIME OUT',e);
    else:
        json1 = json.loads(response2.text)
        return json1
# 添加单个运维一条菜单        
def addItem(origin={}):
    if "name" not in origin:
        print("数据错误2")
        return ""
    shortName = uploadImage(fileurl=origin["img"])["data"]["shortName"]
    parentId = getOperateId()
    moduleColumn = getModueId(origin["mod"])
    if len(shortName) == 0 or len(parentId) == 0 or len(moduleColumn) == 0:
        print("添加错误")
        return ""
    
    dic = dict({
        "empty": 1,
        "id":"",
        "parentId": parentId,
        "name": origin["name"],
        "sort": origin["sort"],
        "moduleColumn": moduleColumn,
        "isPublic": 0,
        "href": origin["url"],
        "iconUrl": shortName,
        "menuType": 1,
        "isShow": 1
    })
    try:
        response = requests.post("https://lzpt.hnzx.gov.cn/platform-lzt/menu/add?",data=dic,headers=header)
    except urllib.error.URLError as e:
        # if isinstance(e.reason, socket.timeout):
        print('TIME OUT',e);
    else:
        json1 = json.loads(response.text)
        return json1

# 批量添加运维工具里操作平台的菜单
def addToSystem(areaName,isAdd=True,ip=""):
    if len(ip) == 0:
        print("IP 不为空")
        return ""
    # 添加法：
    arr = [
        # {
        #     "name":"提案工作",
        #     "mod":"核心业务",
        #     "url":"/workbenchBox/?blank=http://"+ip+"/web.html?red=/tagz/wdta#/?token={{token}}&userId={{userId}}",
        #     "sort":1101,
        #     "img":"/Users/wangshuguan/Documents/政协部署/配图/Web端/核心/提案工作tagz001.png"
        # },
        # {
        #     "name":"社情民意",
        #     "mod":"核心业务",
        #     "url":"/workbenchBox/?blank=http://"+ip+"/web.html?red=/sqmy#/?token={{token}}&userId={{userId}}",
        #     "sort":1102,
        #     "img":"/Users/wangshuguan/Documents/政协部署/配图/Web端/核心/社情民意sqmy001.png"
        # },
        # {
        #     "name":"委员履职",
        #     "mod":"核心业务",
        #     "url":"/workbenchBox/?blank=http://"+ip+"/web.html?red=/lzda/wyta#/?token={{token}}&userId={{userId}}",
        #     "sort":1103,
        #     "img":"/Users/wangshuguan/Documents/政协部署/配图/Web端/核心/委员履职wylz0010.png"
        # },
        # {
        #     "name":"基础信息",
        #     "mod":"核心业务",
        #     "url":"/workbenchBox/?blank=http://"+ip+"/web.html#/?token={{token}}&userId={{userId}}",
        #     "sort":1104,
        #     "img":"/Users/wangshuguan/Documents/政协部署/配图/Web端/核心/基础信息jcxDsaddddd1.png"
        # },


        {
            "name":"会议管理",
            "mod":"自建应用",
            "url":"/workbenchBox?blank=http://"+ip+"/admin.html?red=/conference/list#/login?token={{token}}&userId={{userId}}",
            "sort":1201,
            "img":"/Users/wangshuguan/Documents/政协部署/配图/Web端/自建/会议管理hygl00adfad1sfd0d.png"
        },
        {
            "name":"活动管理",
            "mod":"自建应用",
            "url":"/workbenchBox?blank=http://"+ip+"/admin.html?red=/active/list#/login?token={{token}}&userId={{userId}}",
            "sort":1202,
            "img":"/Users/wangshuguan/Documents/政协部署/配图/Web端/自建/活动管理dd暗藏vzvsdffdffaaaa3.png"
        },
        {
            "name":"智慧党建",
            "mod":"自建应用",
            "url":"/workbenchBox/?blank=http://"+ip+"/djweb.html",
            "sort":1203,
            "img":"/Users/wangshuguan/Documents/政协部署/配图/Web端/自建/智慧党建zh.png"
        },
  

        {
            "name":"淮滨县机关办公平台",
            "mod":"机关办公",
            "url":"/workbenchBox?blank=http://"+ip+"/admin.html#/login",
            "sort":1300,
            "img":"/Users/wangshuguan/Documents/政协部署/配图/Web端/机关办公/通知公告aaacz1.png"
        },
        # {
        #     "name":"通知公告",
        #     "mod":"机关办公",
        #     "url":"/workbenchBox?blank=http://"+ip+"/admin.html?red=/notification/manage/#/login?token={{token}}&userId={{userId}}",
        #     "sort":1301,
        #     "img":"/Users/wangshuguan/Documents/政协部署/配图/Web端/机关办公/通知公告aaacz1.png"
        # },
        # {
        #     "name":"融媒体中心",
        #     "mod":"机关办公",
        #     "url":"/workbenchBox?blank=http://"+ip+"/admin.html?red=/rong/rtupian#/login?token={{token}}&userId={{userId}}",
        #     "sort":1302,
        #     "img":"/Users/wangshuguan/Documents/政协部署/配图/Web端/机关办公/融媒体中心4deeeeeafd.png"
        # },
        # {
        #     "name":"提案管理",
        #     "mod":"机关办公",
        #     "url":"/workbenchBox?blank=http://"+ip+"/admin.html?red=/proposal/firstTrial#/login?token={{token}}&userId={{userId}}",
        #     "sort":1303,
        #     "img":"/Users/wangshuguan/Documents/政协部署/配图/Web端/机关办公/提案审核tash005t.png"
        # },
        # {
        #     "name":"社情民意管理",
        #     "mod":"机关办公",
        #     "url":"/workbenchBox?blank=http://"+ip+"/admin.html?red=/circumstances/sqmycx/list#/login?token={{token}}&userId={{userId}}",
        #     "sort":1304,
        #     "img":"/Users/wangshuguan/Documents/政协部署/配图/Web端/机关办公/社情民意sqmy11dv1d.png"
        # },
        # {
        #     "name":"网络议政",
        #     "mod":"机关办公",
        #     "url":"/workbenchBox?blank=http://"+ip+"/admin.html?red=/netDiscuss/list#/login?token={{token}}&userId={{userId}}",
        #     "sort":1305,
        #     "img":"/Users/wangshuguan/Documents/政协部署/配图/Web端/机关办公/网络议政asfgsgs.png"
        # },
        # {
        #     "name":"书院管理",
        #     "mod":"机关办公",
        #     "url":"/workbenchBox?blank=http://"+ip+"/admin.html?red=/shuyaun/zhidao#/login?token={{token}}&userId={{userId}}",
        #     "sort":1306,
        #     "img":"/Users/wangshuguan/Documents/政协部署/配图/Web端/机关办公/书院管理dd1werRWRWRTWRRFEfv4.png"
        # },
        # {
        #     "name":"政协云盘",
        #     "mod":"机关办公",
        #     "url":"/workbenchBox?blank=http://"+ip+"/admin.html?red=/zxyp/list#/login?token={{token}}&userId={{userId}}",
        #     "sort":1307,
        #     "img":"/Users/wangshuguan/Documents/政协部署/配图/Web端/机关办公/政协云盘4dafdf.png"
        # },
        # {
        #     "name":"统计分析",
        #     "mod":"机关办公",
        #     "url":"/workbenchBox?blank=http://"+ip+"/admin.html?red=/tongji/SocialSituation#/login?token={{token}}&userId={{userId}}",
        #     "sort":1308,
        #     "img":"/Users/wangshuguan/Documents/政协部署/配图/Web端/机关办公/统计分析11sfafadf.png"
        # },
        # {
        #     "name":"短信平台",
        #     "mod":"机关办公",
        #     "url":"/workbenchBox?blank=http://"+ip+"/admin.html?red=/sms/list#/login?token={{token}}&userId={{userId}}",
        #     "sort":1309,
        #     "img":"/Users/wangshuguan/Documents/政协部署/配图/Web端/机关办公/短信平台dsad啊4.png"
        # },
        # {
        #     "name":"政协信息",
        #     "mod":"机关办公",
        #     "url":"/workbenchBox?blank=http://"+ip+"/admin.html?red=/ormsg/intro#/login?token={{token}}&userId={{userId}}",
        #     "sort":1310,
        #     "img":"/Users/wangshuguan/Documents/政协部署/配图/Web端/机关办公/政协信息dasv1CAVA4d.png"
        # },
        # {
        #     "name":"重点工作",
        #     "mod":"机关办公",
        #     "url":"/workbenchBox?blank=http://"+ip+"/admin.html?red=/zdgz/guanli#/login?token={{token}}&userId={{userId}}",
        #     "sort":1311,
        #     "img":"/Users/wangshuguan/Documents/政协部署/配图/Web端/机关办公/重点工作vadsad4345.png"
        # },


        # #  特殊的，后加的
        # {
        #     "name":"委员履职管理",
        #     "mod":"机关办公",
        #     "url":"/workbenchBox?blank=http://"+ip+"/admin.html?red=/memberManage/list#/login?token={{token}}&userId={{userId}}",
        #     "sort":1312,
        #     "img":"/Users/wangshuguan/Documents/政协部署/配图/Web端/核心/委员履职wylz0010.png"
        # },


        # #  默认的 web端配置链接
        # {
        #     "name":f"{areaName}委员履职平台",
        #     "mod":"核心业务",
        #     "url":"/workbenchBox?blank=http://"+ip+"/web.html#/?token={{token}}&userId={{userId}}",
        #     "sort":1101,
        #     "img":"/Users/wangshuguan/Documents/政协部署/配图/Web端/微信图片_20220805160943.png"
        # },
        # {
        #     "name":f"{areaName}机关办公平台",
        #     "mod":"机关办公",
        #     "url":"/workbenchBox?blank=http://"+ip+"/admin.html#/login",
        #     "sort":1102,
        #     "img":"/Users/wangshuguan/Documents/政协部署/配图/Web端/微信图片_20220805160943.png"
        # },
    ]
    for x in arr:
        if isAdd:
            print(addItem(x))
        else:
            # 不可立刻验证，因此最好循环处理
            print(getMenus(name=x["name"],mod = x["mod"])['to'] == x["url"])
        time.sleep(2)

# 批量编辑运维管理操作平台的菜单的url
def editToSystem(isEdit=True,ip=""):
    if len(ip) == 0:
        print("IP 不为空")
        return ""
    # 修改法：
    arr = [
        
        {
            "name":"提案工作",
            "mod":"核心业务",
            "url":"/workbenchBox/?blank=http://"+ip+"/web.html?red=/tagz/wdta#/?token={{token}}&userId={{userId}}",
            "sort":1101,
            "img":"/Users/wangshuguan/Documents/政协部署/配图/Web端/核心/提案工作tagz001.png"
        },
        {
            "name":"社情民意",
            "mod":"核心业务",
            "url":"/workbenchBox/?blank=http://"+ip+"/web.html?red=/sqmy#/?token={{token}}&userId={{userId}}",
            "sort":1102,
            "img":"/Users/wangshuguan/Documents/政协部署/配图/Web端/核心/社情民意sqmy001.png"
        },
        {
            "name":"委员履职",
            "mod":"核心业务",
            "url":"/workbenchBox/?blank=http://"+ip+"/web.html?red=/lzda/wyta#/?token={{token}}&userId={{userId}}",
            "sort":1103,
            "img":"/Users/wangshuguan/Documents/政协部署/配图/Web端/核心/委员履职wylz0010.png"
        },
        {
            "name":"基础信息",
            "mod":"核心业务",
            "url":"/workbenchBox/?blank=http://"+ip+"/web.html#/?token={{token}}&userId={{userId}}",
            "sort":1104,
            "img":"/Users/wangshuguan/Documents/政协部署/配图/Web端/核心/基础信息jcxDsaddddd1.png"
        },


        {
            "name":"会议管理",
            "mod":"自建应用",
            "url":"/workbenchBox?blank=http://"+ip+"/admin.html?red=/conference/list#/login?token={{token}}&userId={{userId}}",
            "sort":1201,
            "img":"/Users/wangshuguan/Documents/政协部署/配图/Web端/自建/会议管理hygl00adfad1sfd0d.png"
        },
        {
            "name":"活动管理",
            "mod":"自建应用",
            "url":"/workbenchBox?blank=http://"+ip+"/admin.html?red=/active/list#/login?token={{token}}&userId={{userId}}",
            "sort":1202,
            "img":"/Users/wangshuguan/Documents/政协部署/配图/Web端/自建/活动管理dd暗藏vzvsdffdffaaaa3.png"
        },
        {
            "name":"智慧党建",
            "mod":"自建应用",
            "url":"/workbenchBox/?blank=http://"+ip+"/djweb.html",
            "sort":1203,
            "img":"/Users/wangshuguan/Documents/政协部署/配图/Web端/自建/智慧党建zh.png"
        },


        {
            "name":"通知公告",
            "mod":"机关办公",
            "url":"/workbenchBox?blank=http://"+ip+"/admin.html?red=/notification/manage/#/login?token={{token}}&userId={{userId}}",
            "sort":1301,
            "img":"/Users/wangshuguan/Documents/政协部署/配图/Web端/机关办公/通知公告aaacz1.png"
        },
        {
            "name":"融媒体中心",
            "mod":"机关办公",
            "url":"/workbenchBox?blank=http://"+ip+"/admin.html?red=/rong/rtupian#/login?token={{token}}&userId={{userId}}",
            "sort":1302,
            "img":"/Users/wangshuguan/Documents/政协部署/配图/Web端/机关办公/融媒体中心4deeeeeafd.png"
        },
        {
            "name":"提案管理",
            "mod":"机关办公",
            "url":"/workbenchBox?blank=http://"+ip+"/admin.html?red=/proposal/firstTrial#/login?token={{token}}&userId={{userId}}",
            "sort":1303,
            "img":"/Users/wangshuguan/Documents/政协部署/配图/Web端/机关办公/提案审核tash005t.png"
        },
        {
            "name":"社情民意管理",
            "mod":"机关办公",
            "url":"/workbenchBox?blank=http://"+ip+"/admin.html?red=/circumstances/sqmycx/list#/login?token={{token}}&userId={{userId}}",
            "sort":1304,
            "img":"/Users/wangshuguan/Documents/政协部署/配图/Web端/机关办公/社情民意sqmy11dv1d.png"
        },
        {
            "name":"网络议政",
            "mod":"机关办公",
            "url":"/workbenchBox?blank=http://"+ip+"/admin.html?red=/netDiscuss/list#/login?token={{token}}&userId={{userId}}",
            "sort":1305,
            "img":"/Users/wangshuguan/Documents/政协部署/配图/Web端/机关办公/网络议政asfgsgs.png"
        },
        {
            "name":"书院管理",
            "mod":"机关办公",
            "url":"/workbenchBox?blank=http://"+ip+"/admin.html?red=/shuyaun/zhidao#/login?token={{token}}&userId={{userId}}",
            "sort":1306,
            "img":"/Users/wangshuguan/Documents/政协部署/配图/Web端/机关办公/书院管理dd1werRWRWRTWRRFEfv4.png"
        },
        {
            "name":"政协云盘",
            "mod":"机关办公",
            "url":"/workbenchBox?blank=http://"+ip+"/admin.html?red=/zxyp/list#/login?token={{token}}&userId={{userId}}",
            "sort":1307,
            "img":"/Users/wangshuguan/Documents/政协部署/配图/Web端/机关办公/政协云盘4dafdf.png"
        },
        {
            "name":"统计分析",
            "mod":"机关办公",
            "url":"/workbenchBox?blank=http://"+ip+"/admin.html?red=/tongji/SocialSituation#/login?token={{token}}&userId={{userId}}",
            "sort":1308,
            "img":"/Users/wangshuguan/Documents/政协部署/配图/Web端/机关办公/统计分析11sfafadf.png"
        },
        {
            "name":"短信平台",
            "mod":"机关办公",
            "url":"/workbenchBox?blank=http://"+ip+"/admin.html?red=/sms/list#/login?token={{token}}&userId={{userId}}",
            "sort":1309,
            "img":"/Users/wangshuguan/Documents/政协部署/配图/Web端/机关办公/短信平台dsad啊4.png"
        },
        {
            "name":"政协信息",
            "mod":"机关办公",
            "url":"/workbenchBox?blank=http://"+ip+"/admin.html?red=/ormsg/intro#/login?token={{token}}&userId={{userId}}",
            "sort":1310,
            "img":"/Users/wangshuguan/Documents/政协部署/配图/Web端/机关办公/政协信息dasv1CAVA4d.png"
        },
        {
            "name":"重点工作",
            "mod":"机关办公",
            "url":"/workbenchBox?blank=http://"+ip+"/admin.html?red=/zdgz/guanli#/login?token={{token}}&userId={{userId}}",
            "sort":1311,
            "img":"/Users/wangshuguan/Documents/政协部署/配图/Web端/机关办公/重点工作vadsad4345.png"
        },
        # {
        #     "name":"委员履职管理",
        #     "mod":"机关办公",
        #     "url":"/workbenchBox?blank=http://"+ip+"/admin.html?red=/memberManage/list#/login?token={{token}}&userId={{userId}}",
        #     "sort":1312,
        #     "img":"/Users/wangshuguan/Documents/政协部署/配图/Web端/核心/委员履职wylz0010.png"
        # },

    ]
    for x in arr:
        if isEdit:
            changeUrl(name=x["name"],mod = x["mod"],url=x["url"])
        # # 不可立刻验证，因此最好循环处理
        else:
            print(getMenus(name=x["name"],mod = x["mod"])['to'] == x["url"])
        time.sleep(2)
# 获取省政协联系人的数据
def getUsers():
#     pageNo: 1
# pageSize: 20
# provinceAreaId: 410882
# groupType: 11
# sex: 
# userName: 
# orderParams: 
# deleId: 
# representerTeam: 
# groupId: 498638375008337920
# committee: 
# isRoutineMember: 
    try:
        response = requests.post("https://lzpt.hnzx.gov.cn/platform-lzt/chatter/provinceList?",data=dict({"provinceAreaId": "410882","pageNo": "1","pageSize": "200"}),headers=header)
    except urllib.error.URLError as e:
        # if isinstance(e.reason, socket.timeout):
        print('TIME OUT',e);
    else:
        json1 = json.loads(response.text)["data"]
        for x in json1:
            print(x["mobile"])
        return json1

# print(getMenus())
def commandTest():
    command = '''
    curl 'https://lzpt.hnzx.gov.cn/platform-lzt/menu/edit?' \
    -X 'POST' \
    -H 'Content-Type: application/x-www-form-urlencoded;charset=UTF-8' \
    -H 'Accept: application/json, text/plain, */*' \
    -H 'Authorization: bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJsb2dpblVzZXIiOnsiaWQiOiI0ODI0MzMzMjMyMzk0NzMxNTIiLCJ1c2VyTmFtZSI6IuW8oOaelyIsIm1vYmlsZSI6IjEzNTI1OTcxNzUyIiwiYWNjb3VudCI6InpoYW5nbGluIiwiaXNVc2luZyI6MSwiZGVsRmxhZyI6MCwiZ3JvdXBpbmdzIjpbeyJhcmVhSWQiOiIwIiwibmFtZSI6IjAifV0sInBhc3N3b3JkIjpudWxsLCJ1c2VybmFtZSI6IjQ4MjQzMzMyMzIzOTQ3MzE1MiIsImVuYWJsZWQiOnRydWUsImF1dGhvcml0aWVzIjpudWxsLCJhY2NvdW50Tm9uRXhwaXJlZCI6dHJ1ZSwiYWNjb3VudE5vbkxvY2tlZCI6dHJ1ZSwiY3JlZGVudGlhbHNOb25FeHBpcmVkIjp0cnVlfSwidXNlcl9uYW1lIjoiNDgyNDMzMzIzMjM5NDczMTUyIiwic2NvcGUiOlsiYWxsIiwicmVhZCIsIndyaXRlIl0sImxvZ2luVXNlcklkIjoiNDgyNDMzMzIzMjM5NDczMTUyIiwiZXhwIjoxNjYzMTQ3MTY4LCJ1dUlkIjoiNzMyODFjM2EtZmE1Ni00OTIzLWEwOTktNWJiNmQxYzNmY2QzIiwianRpIjoiNzMyODFjM2EtZmE1Ni00OTIzLWEwOTktNWJiNmQxYzNmY2QzIiwiY2xpZW50X2lkIjoienlzb2Z0In0.GPnBtzf-HuJTerekjSJZcCoyJ11l3QL6C5NiKBr98-8' \
    -H 'Accept-Language: zh-CN,zh-Hans;q=0.9' \
    -H 'Accept-Encoding: gzip, deflate, br' \
    -H 'Host: lzpt.hnzx.gov.cn' \
    -H 'Origin: https://lzpt.hnzx.gov.cn' \
    -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.6.1 Safari/605.1.15' \
    -H 'Referer: https://lzpt.hnzx.gov.cn/henan-platform/' \
    -H 'Connection: keep-alive' \
    -H 'u-login-areaId: 410305' \
    -H 'clientTypeId: zhengxieplatform' \
    --data 'id=497322258839109632&parentId=446455126362685440&name=%E7%BB%9F%E8%AE%A1%E5%88%86%E6%9E%90&sort=1308&moduleColumn=4&isPublic=0&href=%2FworkbenchBox%3Fblank%3Dhttp%3A%2F%2F111.7.82.133%2Fadmin.html%3Fred%3D%2Ftongji%2FSocialSituation%23%2Flogin%3Ftoken%3D%7B%7Btoken%7D%7D%26userId%3D%7B%7BuserId%7D%7D&iconUrl=%E7%BB%9F%E8%AE%A1%E5%88%86%E6%9E%9011sfafadf.png&menuType=1&isShow=0&nullValueFields=color'
    '''
    print(subprocess.call(command,shell=True))
def accessConfigToDelayTimeout(authorization,areaId,name):
    try:
        response = requests.post("https://lzpt.hnzx.gov.cn/platform-lzt/changearea",headers={
    "Accept": "application/json, text/plain, */*",
    "Authorization": authorization,
    "Accept-Encoding": "gzip, deflate, br",
    "Accept-Language": "zh-CN,zh-Hans;q=0.9",
    "Host": "lzpt.hnzx.gov.cn",
    "Origin": "https://lzpt.hnzx.gov.cn",
    "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.6.1 Safari/605.1.15",
    "Referer": "https://lzpt.hnzx.gov.cn/henan-platform/",
    "u-login-areaId": areaId,
    "clientTypeId": "zhengxieplatform"
})
    except urllib.error.URLError as e:
        # if isinstance(e.reason, socket.timeout):
        print('TIME OUT',e);
    else:
        json1 = {}
        try:
            json1 = json.loads(response.text)["data"]
        except:
            json1 = {}
            return f"{name}-json报错"
        return f"{name}-success" if "token" in json1 else f"{name}-outtime"
def reloadCachedData(imageURLs):
    printStr = ""
    for x in imageURLs:
        with open(x, 'rb') as f:
            dic = json.loads(f.read())
            printStr += accessConfigToDelayTimeout(authorization=dic["tokenhenanzxjava"].replace("\"",""),areaId=dic["areaIdhenanzxjava"].replace("\"",""),name=dic["areaNamehenanzxjava"].replace("\"",""))
            updatetime = datetime.fromtimestamp(os.path.getmtime(x)).strftime("%Y-%m-%d %H:%M:%S")
            printStr += f"-{updatetime}\n"
            time.sleep(2)
    return printStr

if __name__ == "__main__":
    ip = "111.6.83.43:18080"
    # print(addMobileApp(getMobileAddConfig(title = "test", moduleName = "功能区", positionName = "首页中间", sort = "1402", funcName = "核心业务", topMenuName = "功能区", link = "http://www.baidu.com", image = "/Users/wangshuguan/Documents/政协部署/配图/移动端/智慧党建.png")))
    # addMobileApps()
    # updateSession()
    # editToSystem(isEdit=True,ip=ip)
    # addToSystem(isAdd=True,ip=ip)
    # 验证法：
    # print(getMenus(name="统计分析",mod = "机关办公")['to'])
    # print(editApp(origin=getApp(getAppId(name="重点工作管理",mod = "机关办公")),isShow="0"))
    # editAppHiddenToSystem(isEdit=True)
    # print(getUsers())